﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
using System.Diagnostics;
using System.Reflection;

namespace IRC.IRepairClouds.DataLayer.Expressions
{
    partial class Extensions
    {
        public static Expression<TDelegate> Lambda<TDelegate>(this ExpressionBuilder body, params ExpressionBuilder[] parameters)
        {
            return Expression.Lambda<TDelegate>(body, parameters.Select(i => (ParameterExpression)i.Expression).ToArray());
        }

        public static Expression<TDelegate> Lambda<TDelegate>(this ExpressionBuilder body, IEnumerable<ExpressionBuilder> parameters)
        {
            return Expression.Lambda<TDelegate>(body, parameters.Select(i => (ParameterExpression)i.Expression));
        }

        public static Expression<Func<T>> Lambda<T>(this ExpressionBuilder<T> body)
        {
            return Lambda<Func<T>>(body);
        }

        public static Expression<Func<TP1, T>> Lambda<T, TP1>(this ExpressionBuilder<T> body, ParameterExpressionBuilder<TP1> p1)
        {
            return Lambda<Func<TP1, T>>(body, p1);
        }

        public static Expression<Func<TP1, TP2, T>> Lambda<T, TP1, TP2>(this ExpressionBuilder<T> body, ParameterExpressionBuilder<TP1> p1, ParameterExpressionBuilder<TP2> p2)
        {
            return Lambda<Func<TP1, TP2, T>>(body, p1, p2);
        }

        public static Expression<Func<TP1, TP2, TP3, T>> Lambda<T, TP1, TP2, TP3>(this ExpressionBuilder<T> body, ParameterExpressionBuilder<TP1> p1, ParameterExpressionBuilder<TP2> p2, ParameterExpressionBuilder<TP3> p3)
        {
            return Lambda<Func<TP1, TP2, TP3, T>>(body, p1, p2, p3);
        }

        public static Expression<Func<TP1, TP2, TP3, TP4, T>> Lambda<T, TP1, TP2, TP3, TP4>(this ExpressionBuilder<T> body, ParameterExpressionBuilder<TP1> p1, ParameterExpressionBuilder<TP2> p2, ParameterExpressionBuilder<TP3> p3, ParameterExpressionBuilder<TP4> p4)
        {
            return Lambda<Func<TP1, TP2, TP3, TP4, T>>(body, p1, p2, p3, p4);
        }
    }
}
